<?PHP
session_start();
include("../config/connect.php");
include("../public/common.php");

$opt = trim(GetPostParamStr("opt"));
$email = trim(GetPostParamStr("email"));
$nickname = trim(GetPostParamStr("nickname"));
$password = trim(GetPostParamStr("password"));
$sex = trim(GetPostParamStr("sex"));
$phone = trim(GetPostParamStr("phone"));
$account = trim(GetPostParamStr("account"));

if ($opt=="reg")
{
	if ($email=="" || $sex=="" || $nickname=="")
	{
		echo "{'code':0}";
		exit;
	}
	
	$sql = "select * from user where tb_id='$email' limit 1";
	$result = mysql_query( $sql );
	if (mysql_num_rows($result) == 1)
	{
		echo "{'code':1,'has_user':1}";
		exit;
	}
	
	$sql = "insert into user set tb_id='$email',nickname='$nickname',sex=$sex,password='".md5($password)."'";
	$result = mysql_query( $sql );
	if (mysql_affected_rows() == 1)
	{
		$_SESSION["email"] = $email;
		$_SESSION["right"] = 0;
		$_SESSION["userid"] = 0;
		$_SESSION["nickname"] = $nickname;
		echo "{'code':1}";
		exit;
	}
}

echo "{'code':0}";
?>